<?php
include("validar_usuario.php");
require_once("../control/config.class.php");
$executar = new Conexao;
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Untitled Document</title>


<style type="text/css">
.titulo_cad {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #000;
}
.titulo_lab_uni {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #009;
}
.titulo_cad1 {	font-family: Verdana, Geneva, sans-serif;
	font-size: 16px;
	font-weight: bold;
	color: #666;
}
.texto_2 {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 13px;

}
.texto_red {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 13px;
	color: #F00;
}
.texto_3 {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 13px;
		color: #F00;
}
.texto_ {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 15px;
}
.titulo_disponibilidade {	font-family: Verdana, Geneva, sans-serif;
	font-size: 15px;
	font-weight: bold;
}
.link_fe {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 10px;
	font-weight: bold;
	color: #666;
}
</style>
</head>

<script language="javascript">
function carregar_boleto(codigo) {
  
  var check = document.forms["form1"].cpf_cnpj.checked;
  var checked_mensagem = document.forms["form1"].chec_mensagem.checked;
	
  if(check==true){
	  cpf_cnpj_view='cpf_cnpj=1';
  }else{
	  cpf_cnpj_view='cpf_cnpj=0';
  }
  if(checked_mensagem==true){
	  message='message=1&text='+document.form1.mensagem.value;
  }else{
	  message='message=0';
  }
	
  window.open("../view/boleto_bradesco.php?"+cpf_cnpj_view+"&"+message+"&id=" + codigo,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,WIDTH=850,HEIGHT=600,top=50,left=50");	
	
 }

function Habilitar_desabilitar_campos(){
		var message;

        message = document.form1.chec_mensagem.checked;
		if(message == false){
			document.form1.mensagem.disabled = 1; // para ativado
			//document.form1.inicio.value='';
		}else{
			document.form1.mensagem.disabled = 0; // para desativado
			//document.form1.inicio.value='--';
		}
	}
</script>
<body >
<form id="form1" name="form1" method="post" action="">
  <table width="977" border="0" align="center">
    <tr>
      <td height="0" align="center" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td height="0" align="center" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td height="0" align="center" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td><table width="860" border="0" align="center">
        <tr>
          <td width="208" align="right" class="titulo_disponibilidade">Informe o RA/Matricula:</td>
          <td width="185" align="left"><input size="20" name="ra" type="text" id="ra" maxlength="20" style=" font-size:10pt; color: #333333; border: 1px solid #999; background-color: #FFFFFF; height: 20px; " /></td>
          <td width="212" align="center">&nbsp;</td>
        </tr>
        <tr>
          <td height="8" colspan="3" align="center" ></td>
        </tr>
        <tr>
          <td width="208" align="center" >&nbsp;</td>
          <td width="185" align="right"><span class="style7">
            <input type="submit" name="carregar" id="carregar" value="Carregar Boletos " style="background:#666; color:#FFFFFF; border:#000000" />
          </span></td>
          <td width="212" height='8' align="center">&nbsp;</td>
        </tr>
      </table></td>
    </tr>  <?php
  if(isset($_POST['carregar'])){

  ?>
    <tr>
      <td align="right"><table width="623" border="0">
        <tr>
          <td width="23" align="right"><input type="checkbox" name="cpf_cnpj" id="cpf_cnpj" value="<?php echo $dados[0]; ?>"/></td>
          <td width="391" align="left" class="texto_2">Emitir CPF/CNPJ no Boleto</td>
        </tr>
        <tr>
          <td align="right"><input type="checkbox" name="chec_mensagem" id="chec_mensagem" onclick="Habilitar_desabilitar_campos()" value="<?php echo $dados[0]; ?>"/></td>
          <td align="left" class="texto_2">Exibir mensagem no boleto</td>
        </tr>
        <tr>
          <td align="right">&nbsp;</td>
          <td align="left"><select name="mensagem" id="mensagem" style=" font-size:10pt; color: #333333; border: 1px solid #999; background-color: #FFFFFF; height: 24px; width:500px; "  />
            <?php	  

				  $sql="Select mensagem from mensagens; ";
				  $res=$executar->execSQL($sql);
				  if($res){
					  while($dados=mysql_fetch_array($res)){
							  echo "<option value='".$dados[0]."' >".$dados[0]."</option>"; 					 
					  }
				  }

				  ?>
            </select></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td class="titulo_cad">&nbsp;&nbsp;&nbsp;&nbsp;RA/Matricula : <?php echo $_POST['ra']; ?></td>
    </tr>
  
    <tr>
      <td><table width="940" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr class="titulo_cad">
          <td width="114" height="20" align="left" bgcolor="#CCCCCC">N&uacute;mero</td>
          <td width="268" align="left" bgcolor="#CCCCCC">Nome</td>
          <td width="155" height="20" align="left" bgcolor="#CCCCCC">Servi&ccedil;o</td>
          <td width="102" height="20" align="center" bgcolor="#CCCCCC">Per&iacute;odo Letivo</td>
          <td width="77" height="20" align="center" bgcolor="#CCCCCC">Parcela</td>
          <td width="83" height="20" align="center" bgcolor="#CCCCCC">Vencimento</td>
          <td width="75" height="20" align="center" bgcolor="#CCCCCC">Valor</td>
          <td width="66" height="20" bgcolor="#CCCCCC">&nbsp;</td>
        </tr>
        
        <?php
		
		$ra=$_POST['ra'];
		$sql="SELECT b.codigo,b.nome,b.nosso_numero,b.valor,b.periodo_letivo,b.servico_desc,b.parcela,b.matricula,date_format(b.vencimento,'%d/%m/%Y') as vencimento,date_format(b.vencimento,'%Y%m%d') as data_numerica FROM boletos b WHERE b.matricula='".$ra."' and b.filial in (SELECT u.codigo FROM usuarios_unidades uu, unidades_educacionais u where uu.codigo_unidade=u.codigo and uu.codigo_usuario=".$codigo_user.") order by data_numerica; ";
		$cont_boletos=0;
		$data_numerica=date('Ymd');
		$res=$executar->execSQL($sql);
		if($res){
			$cont_boletos=mysql_num_rows($res);
			while($dados=mysql_fetch_array($res)){
				if($dados[9]< $data_numerica){
					$fonte="texto_red";
				}else{
					$fonte="texto_2";
				}
		?>
        
        <tr class="<?php echo $fonte; ?>">
          <td height="20" align="left"><?php echo $dados[2]; ?></td>
          <td align="left"><?php echo utf8_encode($dados[1]); ?></td>
          <td height="20" align="left"><?php echo utf8_encode($dados[5]); ?></td>
          <td height="20" align="center"><?php echo $dados[4]; ?></td>
          <td height="20" align="center"><?php echo $dados[6]; ?></td>
          <td height="20" align="center"><?php echo $dados[8]; ?></td>
          <td height="20" align="center"><?php echo $dados[3]; ?></td>
          <td height="20" align="center"><a href="javascript: carregar_boleto('<?php echo $dados[0]; ?>')"><img src="../img/icone_impressora.gif" border="0" width="18" /></a></td>
        </tr>
         <tr>
            <td height="2" colspan="8" align="center" valign="middle" ><img src="../img/linha_.jpg" width="940" height="1" /></td>
            </tr>
        <?php
	}
		}
		if($cont_boletos>0){
			$texto="Foram encontrados ".$cont_boletos." registros.";
		}else{
			$texto="N&atilde;o foram encontrados registros.";
		}
		?>
        
        <tr class="texto_2">
          <td height="40" colspan="8" align="center"><?php echo $texto; ?></td>
          </tr>
      </table></td>
    </tr>
    <?php
  }
  ?>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<script>
	Habilitar_desabilitar_campos();
</script>
</body>
</html>